package com.yjyw.tiexie.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.yjyw.tiexie.R;
import com.yjyw.tiexie.activity.home.TaskMainActivity;
import com.yjyw.tiexie.bean.BBean;
import com.yjyw.tiexie.bean.TaskBean;
import com.yjyw.tiexie.bean.UserB;
import com.yjyw.tiexie.common.BaseFragment;
import com.yjyw.tiexie.common.net.HandlerCode;
import com.yjyw.tiexie.common.net.NetAPI;
import com.yjyw.tiexie.common.net.NetCallBack;
import com.yjyw.tiexie.db.DaoBUtils;
import com.yjyw.tiexie.db.UserBDBHelper;
import com.yjyw.tiexie.util.GsonUtil;
import com.yjyw.tiexie.util.LogUtil;
import com.yjyw.tiexie.util.SharedPreferencesUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;

public class ActiveMainFragment extends BaseFragment implements NetCallBack {

    @BindView(R.id.iv_start)
    ImageView ivStart;
    private List<TaskBean.DataDTO.ListDTO> list = new ArrayList();

//    private UserBDBHelper mHelper;
    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

        initData();
    }
    @Override
    public void onStart() {
        super.onStart();
//        // 获得数据库帮助器的实例
//        mHelper = UserBDBHelper.getInstance(getActivity());
//        // 打开数据库帮助器的读写连接
//        mHelper.openWriteLink();
//        mHelper.openReadLink();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
//        mHelper.closeLink();
    }

    @Override
    protected int getFragmentView() {
        return R.layout.fragment_active_main;
    }


    private void initData() {
        ivStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //点击巡检之前  检查一下userB表userC表有没有未上传的数据，重新上传一下，然后再清空userB表userC表

                List<BBean>  list1 = DaoBUtils.getInstance().queryByNativeSql("where XJ_TJ_STATUS=? AND XJ_ID_STATUS=?",new String[]{"0","1"});
                LogUtil.e("quertByStatus",list1.size()+"");
                if(list1!= null && list1.size()>0){
                    //有未上传数据 ，提示并且 继续上传

                }else {
                    //开始跳转巡检页面
                    LogUtil.e("quertByStatus","开始跳转巡检页面");
                    getActivity().startActivity(new Intent(getActivity(), TaskMainActivity.class));
                }
            }
        });
    }


    @Override
    public void onResponse(boolean flag, int requestCode, String result) throws Exception {
        switch (requestCode){
            case HandlerCode.GET_TASK_LIST:
                break;
        }
    }

    @Override
    public void tokenTimeOut(int requestCode) {

    }
}
